package com.lunevich.demo;

import com.lunevich.demo.helpers.DownloadManager;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

public class ImageAdapter extends BaseAdapter {

	private static final String[] URLS = {
			"http://a3.twimg.com/profile_images/681537837/SmallAvatarx150_normal.png",
			"http://a1.twimg.com/profile_images/63737974/2008-11-06_1637_normal.png",
			"http://a3.twimg.com/profile_images/548410609/icon_8_73.png",
			"http://a1.twimg.com/profile_images/612232882/nexusoneavatar_normal.jpg",
			"http://a1.twimg.com/profile_images/213722080/Bugdroid-phone_normal.png",
			"http://a1.twimg.com/profile_images/645523828/OT_icon_090918_android_normal.png",
			"http://a3.twimg.com/profile_images/64827025/android-wallpaper6_2560x160_normal.png",
			"http://a3.twimg.com/profile_images/77641093/AndroidPlanet.png",
			"http://a1.twimg.com/profile_images/850960042/elandroidelibre-logo_300x300_normal.jpg",
			"http://a1.twimg.com/profile_images/655119538/andbook_normal.png",
			"http://a3.twimg.com/profile_images/511790713/AG_normal.png",
			"http://a3.twimg.com/profile_images/956404323/androinica-avatar.png",
			"http://a1.twimg.com/profile_images/909231146/Android_Biz_Man_normal.png",
			"http://a3.twimg.com/profile_images/72774055/AndroidHomme-LOGO_normal.jpg",
			"http://a1.twimg.com/profile_images/349012784/android_logo_small_normal.jpg",
			"http://a1.twimg.com/profile_images/841338368/ea-twitter-icon_normal.png",
			"http://a3.twimg.com/profile_images/64827025/android-wallpaper6_2560x160_normal.png",
			"http://a3.twimg.com/profile_images/77641093/AndroidPlanet.png",
			"http://a3.twimg.com/profile_images/64827025/android-wallpaper6_2560x160_normal.png",
			"http://a3.twimg.com/profile_images/77641093/AndroidPlanet_normal.png",
			"http://a1.twimg.com/profile_images/850960042/elandroidelibre-logo_300x300.jpg",
			"http://a1.twimg.com/profile_images/655119538/andbook_normal.png",
			"http://a3.twimg.com/profile_images/511790713/AG_normal.png",
			"http://a3.twimg.com/profile_images/956404323/androinica-avatar_normal.png",
			"http://a1.twimg.com/profile_images/909231146/Android_Biz_Man_normal.png",
			"http://a3.twimg.com/profile_images/121630227/Droid.jpg",
			"http://a1.twimg.com/profile_images/957149154/twitterhalf_normal.jpg",
			"http://a1.twimg.com/profile_images/97470808/icon_normal.png",
			"http://a3.twimg.com/profile_images/511790713/AG_normal.png",
			"http://a3.twimg.com/profile_images/956404323/androinica-avatar_normal.png",
			"http://a1.twimg.com/profile_images/909231146/Android_Biz_Man.png",
			"http://a3.twimg.com/profile_images/72774055/AndroidHomme-LOGO_normal.jpg",
			"http://a1.twimg.com/profile_images/349012784/android_logo_small_normal.jpg",
			"http://a1.twimg.com/profile_images/841338368/ea-twitter-icon_normal.png",
			"http://a3.twimg.com/profile_images/64827025/android-wallpaper6_2560x160_normal.png",
			"http://a3.twimg.com/profile_images/77641093/AndroidPlanet.png",
			"http://a3.twimg.com/profile_images/670625317/aam-logo-v3-twitter_normal.png",
			"http://a3.twimg.com/profile_images/740897825/AndroidCast-350_normal.png",
			"http://a3.twimg.com/profile_images/121630227/Droid_normal.jpg",
			"http://a1.twimg.com/profile_images/957149154/twitterhalf_normal.jpg",
			"http://a1.twimg.com/profile_images/97470808/icon.png",
			"http://a3.twimg.com/profile_images/511790713/AG_normal.png",
			"http://a3.twimg.com/profile_images/956404323/androinica-avatar_normal.png",
			"http://a1.twimg.com/profile_images/909231146/Android_Biz_Man_normal.png",
			"http://a3.twimg.com/profile_images/72774055/AndroidHomme-LOGO_normal.jpg",
			"http://a1.twimg.com/profile_images/349012784/android_logo_small_normal.jpg",
			"http://a1.twimg.com/profile_images/841338368/ea-twitter-icon.png",
			"http://a3.twimg.com/profile_images/64827025/android-wallpaper6_2560x160_normal.png",
			"http://a3.twimg.com/profile_images/77641093/AndroidPlanet_normal.png",
			"http://a1.twimg.com/profile_images/850960042/elandroidelibre-logo_300x300_normal.jpg",
			"http://a1.twimg.com/profile_images/655119538/andbook_normal.png",
			"http://a3.twimg.com/profile_images/768060227/ap4u_normal.jpg",
			"http://a1.twimg.com/profile_images/74724754/android_logo.png",
			"http://a3.twimg.com/profile_images/681537837/SmallAvatarx150_normal.png",
			"http://a1.twimg.com/profile_images/63737974/2008-11-06_1637_normal.png",
			"http://a3.twimg.com/profile_images/548410609/icon_8_73_normal.png",
			"http://a1.twimg.com/profile_images/612232882/nexusoneavatar_normal.jpg",
			"http://a1.twimg.com/profile_images/213722080/Bugdroid-phone_normal.png",
			"http://a1.twimg.com/profile_images/645523828/OT_icon_090918_android.png",
			"http://a3.twimg.com/profile_images/64827025/android-wallpaper6_2560x160_normal.png",
			"http://a3.twimg.com/profile_images/77641093/AndroidPlanet_normal.png",
			"http://a1.twimg.com/profile_images/850960042/elandroidelibre-logo_300x300_normal.jpg",
			"http://a1.twimg.com/profile_images/655119538/andbook.png",
			"http://a3.twimg.com/profile_images/511790713/AG_normal.png",
			"http://a3.twimg.com/profile_images/956404323/androinica-avatar_normal.png",
			"http://a1.twimg.com/profile_images/909231146/Android_Biz_Man_normal.png",
			"http://a3.twimg.com/profile_images/72774055/AndroidHomme-LOGO_normal.jpg",
			"http://a1.twimg.com/profile_images/349012784/android_logo_small_normal.jpg",
			"http://a1.twimg.com/profile_images/841338368/ea-twitter-icon.png",
			"http://a3.twimg.com/profile_images/64827025/android-wallpaper6_2560x160_normal.png",
			"http://a3.twimg.com/profile_images/77641093/AndroidPlanet_normal.png",
			"http://a3.twimg.com/profile_images/64827025/android-wallpaper6_2560x160_normal.png",
			"http://a3.twimg.com/profile_images/77641093/AndroidPlanet_normal.png",
			"http://a1.twimg.com/profile_images/850960042/elandroidelibre-logo_300x300_normal.jpg",
			"http://a1.twimg.com/profile_images/655119538/andbook_normal.png",
			"http://a1.twimg.com/profile_images/909231146/Android_Biz_Man_normal.png",
			"http://a3.twimg.com/profile_images/72774055/AndroidHomme-LOGO_normal.jpg",
			"http://a1.twimg.com/profile_images/349012784/android_logo_small.jpg",
			"http://a1.twimg.com/profile_images/841338368/ea-twitter-icon_normal.png",
			"http://a3.twimg.com/profile_images/64827025/android-wallpaper6_2560x160_normal.png",
			"http://a3.twimg.com/profile_images/77641093/AndroidPlanet_normal.png" };

	private Context context;
	private ImageView imageView;

	public ImageAdapter(Context context) {
		this.context = context;
	}

	@Override
	public int getCount() {
		return URLS.length;
	}

	@Override
	public Object getItem(int position) {
		return URLS[position];
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = inflater.inflate(R.layout.row, parent, false);
		}

		imageView = (ImageView) convertView.findViewById(R.id.imageView1);
		DownloadManager.getImageDownloader(context).download(URLS[position], imageView, this);

		return convertView;
	}
}
